package com.wrb.pwd;


import com.wrb.pwd.component.MainCardLayout;
import com.wrb.pwd.component.PasswordCheckDialog;
import com.wrb.pwd.component.UserListPanel;
import com.wrb.pwd.config.RePackageThread;
import com.wrb.pwd.service.UserService;

import javax.swing.*;
import java.awt.*;
import java.io.IOException;
import java.net.ServerSocket;

/**
 * @author wrb
 * @date 2019/9/12 15:49
 */
public class Main {

	public static void main(String[] args) {
		//设置程序只能运行一次
		int port = 7777;

		if (isRunning(port)) {
			JOptionPane.showMessageDialog(null, "程序已经运行或" + port + "端口被占用！", "错误 ", 0);
			return;
		}

		//输入密码进入
		PasswordCheckDialog dialog = new PasswordCheckDialog( null);
		int state = dialog.getReturnStatus();
		if (state == 0) {
			dialog.dispose();
			return;
		}

		//程序结束后将生成数据打包进jar包
		RePackageThread rePackageThread = new RePackageThread();
		Runtime.getRuntime().addShutdownHook(rePackageThread);

		MainCardLayout.getInstance();
	}

	private static boolean isRunning(int port) {
		try {
			new ServerSocket(port);
			return false;
		} catch (IOException e) {
			return true;
		}
	}
}
